from .base_event import BaseEvent
import sys
import inspect

ALL_REGISTERED_EVENTS = {}


def _register_subclasses():
    """动态扫描当前包内所有模块"""
    from pathlib import Path
    import importlib

    package_dir = Path(__file__).parent
    for py_file in package_dir.glob("*.py"):
        if py_file.name.startswith('_') or py_file.name == 'base.py':
            continue

        module_name = f"{package_dir.name}.{py_file.stem}"
        module = sys.modules.get(module_name)
        if not module:
            module = importlib.import_module(module_name)

        for name, obj in inspect.getmembers(module):
            if (inspect.isclass(obj)
                    and issubclass(obj, BaseEvent)
                    and obj is not BaseEvent):
                ALL_REGISTERED_EVENTS[name] = obj


_register_subclasses()
